﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using Kevin.Shop.Business.Service.Entity.Core.Member;
using RiderShop.Mobile.Modle;
using Kevin.Shop.Business.Core.Components;
using Kevin.Shop.Business.Products.Components;
using Kevin.Shop.Business.Service.Entity.Products.Enumerations;
using System.Collections.Specialized;
using RiderShop.Mobile.Common.Component;
using Kevin.Shop.Business.Comments.Components;
using RiderShop.Mobile.Modle;
using RiderShop.Mobile.ServiceEntity.Product;
using Kevin.Shop.Business.Service.Entity.SalesManagement.Shipping;
using Kevin.Shop.Business.Core.Components.Responser;
using RiderShop.Mobile.ServiceEntity.MyAccount;
using Kevin.Shop.Business.Service.Entity.Helper;
using RiderShop.Mobile.ServiceEntity;
using RiderShop.Mobile.Modle.MyAccount;
using Kevin.Shop.Business.Service.Entity.Core.Enumerations;

namespace RiderShop.Mobile.Controllers.MyAccount
{
    public partial class MyAccountController : ThemeController
    {
        #region get my all point
        /// <summary>
        /// 我的我的全部积分列表
        /// </summary>
        /// <param name="pageIndex">当前页的索引</param>
        /// <returns>积分集合</returns>
        [HttpGet]
        [Authorize]
        public ActionResult MyPoint(int pageIndex = 0, int pageSize = 20)
        {
            MyPointModel myPointModel = new MyPointModel();
            myPointModel.GetUserPoint(pageIndex, pageSize);

            return View(WebClientContext.Current.SiteTheme, "MyAccount", "MyPoint", WebClientContext.Current.CacheKeyDefaultMasterPage, myPointModel);
        }

        /// <summary>
        /// 得到我的全部积分列表
        /// </summary>
        /// <param name="pageIndex">当前页的索引</param>
        /// <returns>积分集合</returns>
        [HttpGet]
        public ActionResult MyPointByAjaxRequest(int pageIndex, int pageSize = 20)
        {
            MyPointModel myPointModel = new MyPointModel();
            DbQueryResult<List<CustomerPointInfo>> result = myPointModel.GetUserPoint(pageIndex, pageSize);

            return PartialView(WebClientContext.Current.SiteTheme, "MyAccount", "MyPointPartial", myPointModel);
        }
        #endregion


        #region 签到
        [HttpGet]
        [Authorize]
        public ActionResult PointCheckIn()
        {
            MyPointModel myPointModel = new MyPointModel();
            var query = new CustomerPointQuery()
            {
                PageIndex = 0,
                PageSize = 10,
                TradeType = Kevin.Shop.Business.StoreManagement.Enumerations.PonitTradeType.AddByCheckIn,
                UserId = WebClientContext.Current.UserId
            };
            myPointModel.GetUserPoint(query);

            return View(WebClientContext.Current.SiteTheme, "MyAccount", "PointCheckIn", WebClientContext.Current.CacheKeyDefaultMasterPage, myPointModel);
        }

        [HttpPost]
        [Authorize]
        public JsonResult PointUserCheckIn()
        {
            MyPointModel myPointModel = new MyPointModel();
            var res = myPointModel.UserCheckIn();

            return Json(res);
        }

        [Authorize]
        [HttpGet]
        public ActionResult PointCheckInRewards()
        {
            MyPointModel myPointModel = new MyPointModel();

            if (Request.IsAjaxRequest())
            {
                return Json(myPointModel.CheckInRewards(false), JsonRequestBehavior.AllowGet);
            }
            var res = myPointModel.CheckInRewards(true);


            return View(WebClientContext.Current.SiteTheme, "MyAccount", "PointCheckInRewards", WebClientContext.Current.CacheKeyDefaultMasterPage, res);
        }
        #endregion
    }
}
